Skip to content

csnode: validate CompressedRegion before decompressing (remote crash during sync) - #4

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/compressor-validate-region
Oct 8, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/compressor-validate-region

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Problem: remote crash of a syncing node

Compressor::decompress() trusts the region it is given. In Node::getBlockReply both the region and its binarySize come straight from a peer's packet (operator>>(IDataStream&, CompressedRegion&)), so a single packet can take down a syncing node:

Malicious input Effect before the fix
huge binarySize bytes.resize() throws std::bad_alloc/length_error, nothing on the transport thread catches it, and the process terminates
empty region the "not compressed" branch computes size = 0 - 1 and reads from nullptr + 1: SIGSEGV

Fix (csnode/include/csnode/compressor.hpp, +18)

Both cases are rejected before touching memory, returning T{}, which is what decompress() already does when LZ4 fails. Callers already handle an empty result ("No pools found").

  • An empty region is rejected.
  • A compressed region is rejected when binarySize exceeds INT_MAX (LZ4 works with int sizes) or 256 x the compressed size. LZ4 cannot expand data more than 255:1, so no region produced by compress() is affected.

Tests (tests/csnode/compressor_tests.cpp)

Test Before After
Compressor.RejectsBinarySizeLz4CannotProduce throws std::bad_alloc ✅
Compressor.RejectsEmptyRegion SIGSEGV ✅
full nodetests — 112/112

Upstream

A single commit that applies as is to CREDITSCOM/node, where compressor.hpp is identical. It does not depend on the fork's CI.

🤖 Generated with Claude Code

Compressor::decompress() trusts the region it is given. In
Node::getBlockReply that region, and its binary size, are read straight from
a peer's packet (operator>>(IDataStream&, CompressedRegion&)), so one packet
can take down a syncing node:

- binarySize is an arbitrary size_t. bytes.resize(binarySize) throws
  std::length_error/std::bad_alloc, nothing on the transport thread catches
  it, and the node terminates.
- An empty region (data() == nullptr, size() == 0) takes the "not compressed"
  branch with size = 0 - 1 and reads from nullptr + 1: SIGSEGV.

Reject both before touching memory and return T{}, as decompress() already
does when LZ4 fails. Callers already handle an empty result ("No pools
found").

- An empty region is rejected.
- A compressed region is rejected when binarySize exceeds INT_MAX (LZ4 works
  with int sizes) or 256 x the compressed size. LZ4 cannot expand data more
  than 255:1, so no region produced by compress() is affected.

Tests (tests/csnode/compressor_tests.cpp):
- Compressor.RejectsBinarySizeLz4CannotProduce: before the fix it throws
  std::bad_alloc.
- Compressor.RejectsEmptyRegion: before the fix it crashes with SIGSEGV.
nodetests: 112/112 pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit ea2efe9 into master Oct 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant